//#define USE_ARTAG

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using GoblinXNA;
using GoblinXNA.Graphics;
using GoblinXNA.SceneGraph;
using Model = GoblinXNA.Graphics.Model;
using GoblinXNA.Graphics.Geometry;
using GoblinXNA.Device.Capture;
using GoblinXNA.Device.Vision;
using GoblinXNA.Device.Vision.Marker;
using GoblinXNA.Device.Util;
using GoblinXNA.Physics;
using GoblinXNA.Physics.Newton1;
using GoblinXNA.Helpers;

using GoblinXNA.Device.Generic;//keyboard


namespace Tutorial8___Optical_Marker_Tracking
{
    /// <summary>
    /// This tutorial demonstrates how to use both the ALVAR and ARTag optical marker tracker 
    /// library with our Goblin XNA framework. Please read the README.pdf included with this 
    /// project before running this tutorial. If you're using ARTag, please remove calib.xml
    /// from the solution explorer so that you can successfully build the project. 
    /// </summary>
    public class Tutorial8 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        Scene scene;
        MarkerNode groundMarkerNode, miniMapMarkerNode, groundReferenceMarkerNode, speedMarkerNode;
        GeometryNode groundNode, boxNode, realgroundNode;
        GeometryNode[] wallNode;
        TransformNode[] wallTransNode;
        Material[] wallMaterial;

        TransformNode rootTransNode1, rootTransNode2, travelFirstTransNode, travelSecTransNode,travelThirdTransNode, boxTransNode1, boxTransNode2, realgroundTransNode;
        Vector3 cameraPos = new Vector3(0, 0, 0), groundRefPos, cameraDelt,carPos;
        float travelTranslationY = 0;
        double miniUpdateAngle, miniInitAngle, miniMapRotateDegree=0, rotateScope=20, groundRefAngle, speedUpdateAngle, speedInitAngle;

        int wallindex = 0;
        int iniWallSize = 10;
        int cmrSetNum = 0;
        bool debug = true;
        bool travelMode = false;
        bool miniMapUpdateOnce = false, cameraAlreadySet=false,groundAlreadySet=false,carPosAlreadySet=false, speedControlUpdateOnce=false;

        public Tutorial8()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Initialize the GoblinXNA framework
            State.InitGoblin(graphics, Content, "");

            // Initialize the scene graph
            scene = new Scene(this);

            // Use the newton physics engine to perform collision detection
            scene.PhysicsEngine = new NewtonPhysics();
        //    scene.PhysicsEngine.GravityDirection = new Vector3(0, 0, 0);

            // For some reason, it causes memory conflict when it attempts to update the
            // marker transformation in the multi-threaded code, so if you're using ARTag
            // then you should not enable the marker tracking thread
#if !USE_ARTAG
            State.ThreadOption = (ushort)ThreadOptions.MarkerTracking;
#endif

            // Set up optical marker tracking
            // Note that we don't create our own camera when we use optical marker
            // tracking. It'll be created automatically
            SetupMarkerTracking();

            // Set up the lights used in the scene
            CreateLights();

            // Create the ground that represents the physical ground marker array
            CreateGround();

            // Create 3D objects
            CreateObjects();

            // Use per pixel lighting for better quality (If you using non NVidia graphics card,
            // setting this to true may reduce the performance significantly)
            scene.PreferPerPixelLighting = true;

            // Enable shadow mapping
            // NOTE: In order to use shadow mapping, you will need to add 'PostScreenShadowBlur.fx'
            // and 'ShadowMap.fx' shader files as well as 'ShadowDistanceFadeoutMap.dds' texture file
            // to your 'Content' directory
            scene.EnableShadowMapping = true;

            // Show Frames-Per-Second on the screen for debugging
            State.ShowFPS = true;

            // Add a keyboard press handler for user input
            KeyboardInput.Instance.KeyPressEvent += new HandleKeyPress(KeyPressHandler);

            base.Initialize();
        }

        private void CreateLights()
        {
            // Create a directional light source
            LightSource lightSource = new LightSource();
            lightSource.Direction = new Vector3(1, -1, -1);
            lightSource.Diffuse = Color.White.ToVector4();
            lightSource.Specular = new Vector4(0.6f, 0.6f, 0.6f, 1);

            // Create a light node to hold the light source
            LightNode lightNode = new LightNode();
            lightNode.LightSource = lightSource;

            scene.RootNode.AddChild(lightNode);
        }

        private void SetupMarkerTracking()
        {
            // Create our video capture device that uses DirectShow library. Note that 
            // the combinations of resolution and frame rate that are allowed depend on 
            // the particular video capture device. Thus, setting incorrect resolution 
            // and frame rate values may cause exceptions or simply be ignored, depending 
            // on the device driver.  The values set here will work for a Microsoft VX 6000, 
            // and many other webcams.
            DirectShowCapture captureDevice = new DirectShowCapture();
            captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._640x480,
                ImageFormat.R8G8B8_24, false);

            // Add this video capture device to the scene so that it can be used for
            // the marker tracker
            scene.AddVideoCaptureDevice(captureDevice);

            IMarkerTracker tracker = null;

#if USE_ARTAG
            // Create an optical marker tracker that uses ARTag library
            tracker = new ARTagTracker();
            // Set the configuration file to look for the marker specifications
            tracker.InitTracker(638.052f, 633.673f, captureDevice.Width,
                captureDevice.Height, false, "ARTag.cf");
#else
            // Create an optical marker tracker that uses ALVAR library
            tracker = new ALVARMarkerTracker();
            ((ALVARMarkerTracker)tracker).MaxMarkerError = 0.02f;
            tracker.InitTracker(captureDevice.Width, captureDevice.Height, "calib.xml", 9.0);
#endif

            // Set the marker tracker to use for our scene
            scene.MarkerTracker = tracker;

            // Display the camera image in the background. Note that this parameter should
            // be set after adding at least one video capture device to the Scene class.
            scene.ShowCameraImage = true;
        }

        private void CreateGround()
        {
            groundNode = new GeometryNode("Ground");
            groundNode.Model = new Box(90f, 120f, 0.1f);

            // Set this ground model to act as an occluder so that it appears transparent
            groundNode.IsOccluder = true;

            // Make the ground model to receive shadow casted by other objects with
            // CastShadows set to true
            groundNode.Model.ReceiveShadows = true;

            Material groundMaterial = new Material();
            groundMaterial.Diffuse = Color.Gray.ToVector4();
            groundMaterial.Specular = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            groundNode.Material = groundMaterial;

           // groundMarkerNode.AddChild(groundNode);
        }

        private void CreateObjects()
        {
            wallNode = new GeometryNode[100];
            wallMaterial = new Material[100];
            wallTransNode = new TransformNode[100];

            // Create a marker node to track a ground marker array.
            groundMarkerNode = new MarkerNode(scene.MarkerTracker, "20-59_ALVAR_groundArray.txt");
            scene.RootNode.AddChild(groundMarkerNode);

            //Create the marker node for the minimap
            miniMapMarkerNode = new MarkerNode(scene.MarkerTracker, "1-4_ALVAR_MiniMap.txt");
            scene.RootNode.AddChild(miniMapMarkerNode);

            groundReferenceMarkerNode = new MarkerNode(scene.MarkerTracker, "7-8_ALVAR_Hand2.txt");
            scene.RootNode.AddChild(groundReferenceMarkerNode);

            speedMarkerNode = new MarkerNode(scene.MarkerTracker, "0_ALVAR_speedControl.txt");
            scene.RootNode.AddChild(speedMarkerNode);

            rootTransNode1 = new TransformNode("rootTransNode1");
            rootTransNode2 = new TransformNode("rootTransNode2");
            //groundMarkerNode.AddChild(rootTransNode);
           
            groundMarkerNode.AddChild(rootTransNode2);
            rootTransNode2.AddChild(rootTransNode1);
            rootTransNode1.AddChild(groundNode);
           

            boxNode = new GeometryNode("Box");
            boxNode.Model = new Box(8);
            boxNode.AddToPhysicsEngine = true;
            boxNode.Physics.Shape = ShapeType.Box;
            boxNode.Model.CastShadows = false;
            boxNode.Model.ReceiveShadows = true;
            Material boxMaterial = new Material();
            boxMaterial.Diffuse = new Vector4(0.6f, 0.5f, 0.5f, 0.8f);
            boxMaterial.Specular = Color.White.ToVector4();
            boxMaterial.SpecularPower = 10;
            boxNode.Material = boxMaterial;
          //  boxTransNode1 = new TransformNode();
            boxTransNode2 = new TransformNode();
            boxTransNode2.Translation = new Vector3(30,-30,2);
            groundNode.AddChild(boxTransNode2);
            //boxTransNode2.AddChild(boxTransNode1);
            boxTransNode2.AddChild(boxNode);

            realgroundNode = new GeometryNode("RealGround");
            realgroundNode.Model = new Box(90,120,0.1f);
           // realgroundNode.AddToPhysicsEngine = true;
           // realgroundNode.Physics.Shape = ShapeType.Box;
            realgroundNode.Model.CastShadows = true;
            realgroundNode.Model.ReceiveShadows = true;
            Material realgroundMaterial = new Material();
            realgroundMaterial.Diffuse = Color.Gray.ToVector4();
           // realgroundMaterial.Diffuse = Color.TransparentWhite.ToVector4();
            realgroundMaterial.Specular = Color.White.ToVector4();
            realgroundMaterial.SpecularPower = 10;
            realgroundNode.Material = realgroundMaterial;
            realgroundTransNode = new TransformNode();
            realgroundTransNode.Translation = new Vector3(40, -58, 1);
            travelFirstTransNode = new TransformNode("travelFirstTransNode");
            travelSecTransNode = new TransformNode("travelSecTransNode");
            travelThirdTransNode = new TransformNode();
            groundNode.AddChild(travelFirstTransNode);
            travelFirstTransNode.AddChild(travelSecTransNode);
            travelSecTransNode.AddChild(travelThirdTransNode);
            travelThirdTransNode.AddChild(realgroundTransNode);
            realgroundTransNode.AddChild(realgroundNode);
            initMap();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            Content.Unload();
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //travelFirstTransNode.Translation = new Vector3(0, travelTranslationY, 0);

           /* if (travelMode == true)
            {
                rootTransNode1.Scale = new Vector3(10, 10, 10);
                Vector3 temp=cameraPos-new Vector3(0,0,10);
                rootTransNode2.Translation = temp - boxNode.WorldTransformation.Translation;           
            }
            else
                rootTransNode1.Scale = new Vector3(1, 1, 1);*/
           
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (groundMarkerNode.MarkerFound)
            {
              // if(!groundAlreadySet)
                if (groundReferenceMarkerNode.MarkerFound)
                {
                    Vector3 baseVect = Vector3.Transform(new Vector3(1, 0, 0), groundMarkerNode.WorldTransformation * Matrix.Invert(groundReferenceMarkerNode.WorldTransformation)) -
                                   Vector3.Transform(new Vector3(0, 0, 0), groundMarkerNode.WorldTransformation * Matrix.Invert(groundReferenceMarkerNode.WorldTransformation));
                    baseVect.Normalize();
                    Vector3 temp = new Vector3(1, 0, 0);
                  //  groundRefPos = Vector3.Transform(new Vector3(4, -4, 2), groundReferenceMarkerNode.WorldTransformation * Matrix.Invert(groundMarkerNode.WorldTransformation));
                    groundRefAngle = System.Math.Acos(Vector3.Dot(temp, baseVect));
                    //Console.WriteLine(180 * groundRefAngle / System.Math.PI);
                    //Vector3 t1 = Matrix.Invert(groundMarkerNode.WorldTransformation).Translation;
                    //Vector3 t2 = Matrix.Invert(groundReferenceMarkerNode.WorldTransformation).Translation;
                    //Vector3 t = t1 - t2;
                    //Console.WriteLine(t.Length());
                
                   // Console.WriteLine(groundRefPos);
                    groundRefPos = new Vector3(-90, 0, 0);
                }
                rootTransNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, (float)groundRefAngle);
                rootTransNode1.Translation = groundRefPos;
               
                cameraPos = SetCameraPos();
              
                if (miniMapMarkerNode.MarkerFound)
                {
                   // Console.WriteLine("found!!!");
                    if (!miniMapUpdateOnce)
                    {
                        UpdateMiniMapAngle();
                        miniInitAngle = miniUpdateAngle;
                        miniMapUpdateOnce = true;
                    }
                    else
                    {
                     
                            UpdateMiniMapAngle();
                            double deltAngle;
                            if (miniUpdateAngle <= 85 || miniUpdateAngle >= 95)
                                deltAngle = miniUpdateAngle - miniInitAngle;
                            else
                                deltAngle = 0;
                                //Console.WriteLine(deltAngle);
                                miniMapRotateDegree += deltAngle * 0.006 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                                // Vector3 miniMapPos=Vector3.Transform(new Vector3(0, 0, 0), groundNode.WorldTransformation * 
                                //     Matrix.Invert(miniMapMarkerNode.WorldTransformation));
                                travelSecTransNode.Translation = -boxTransNode2.Translation;
                                travelFirstTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)miniMapRotateDegree);
                                travelFirstTransNode.Translation = boxTransNode2.Translation;
                                //miniInitAngle = miniUpdateAngle;
                            
                    }

                    if (speedMarkerNode.MarkerFound)
                    {
                        Console.WriteLine((float)gameTime.ElapsedGameTime.TotalSeconds);
                        if (!speedControlUpdateOnce)
                        {
                            UpdateSpeedControlAngle();
                            speedInitAngle = speedUpdateAngle;
                            speedControlUpdateOnce = true;
                        }
                        else
                        {
                            UpdateSpeedControlAngle();
                            double deltAngle;
                            if (speedUpdateAngle <= 5 || speedUpdateAngle >= -5)
                                deltAngle = 0;
                            else
                                deltAngle = speedUpdateAngle - speedInitAngle;
                          //  Console.WriteLine(deltAngle);
                            /////add speed translation into travelThirdTransNode.Translation;
                        }
                    }
                }

               

                if (travelMode)
                {
                    rootTransNode1.Scale = new Vector3(4, 4, 4);
                    boxTransNode2.Scale = new Vector3(0.25f, 0.25f, 0.25f);
                    if (!carPosAlreadySet)
                    {
                        carPos = Vector3.Transform(boxTransNode2.Translation+new Vector3(70,-90,10),
                              rootTransNode1.WorldTransformation);
                        carPosAlreadySet = true;
                    }
                   // if (!cameraAlreadySet)
                    //{
                    Vector3 temp = cameraPos;
                        cameraDelt = temp - carPos;
                       // Console.WriteLine("box:" + Vector3.Transform(boxTransNode2.Translation,
                        //       rootTransNode2.WorldTransformation * rootTransNode1.WorldTransformation));
                       // Console.WriteLine("camera:" + temp);
                        //Console.WriteLine(cameraPos - Vector3.Transform(boxTransNode2.Translation,
                        //       rootTransNode2.WorldTransformation * rootTransNode1.WorldTransformation));
                  
                        rootTransNode2.Translation = cameraDelt;
                        
                        
                    //   cameraAlreadySet = true;
                    //}
                    //else
                    //{
                    //    Vector3 temp = cameraPos - new Vector3(0, 0, 10);
                    //    rootTransNode2.Translation = cameraDelt;
                    //    boxTransNode2.Translation = temp - boxNode.WorldTransformation.Translation;
                    //}

                }
                else
                {
                    rootTransNode1.Scale = new Vector3(1, 1, 1);
                    rootTransNode2.Translation = new Vector3(0,0,0);
                    boxTransNode2.Scale= new Vector3(1, 1, 1);
                }
            }
            base.Draw(gameTime);
        }

        /////save the camera's position relative to the ground--by Xueying
        private Vector3 SetCameraPos()
        {
            return Matrix.Invert(groundMarkerNode.WorldTransformation).Translation;
           // return groundMarkerNode.WorldTransformation.Translation;
        }

        //Update minimap's rotation angle respect to the ground--by Sheryn
        private void UpdateMiniMapAngle()
        {
            Vector3 miniBaseVector = new Vector3(1, 0, 0);
            Vector3 miniControlVector = Vector3.Transform(new Vector3(1, 0, 0), groundMarkerNode.WorldTransformation* Matrix.Invert(miniMapMarkerNode.WorldTransformation)) -
                Vector3.Transform(new Vector3(0, 0, 0), groundMarkerNode.WorldTransformation * Matrix.Invert(miniMapMarkerNode.WorldTransformation)) ;
            miniControlVector.Z = 0; miniControlVector.Normalize();
            miniUpdateAngle = 180* System.Math.Acos(Vector3.Dot(miniBaseVector, miniControlVector)) / System.Math.PI;
           
        }

        private void UpdateSpeedControlAngle()
        {
            Vector3 speedBaseVector = new Vector3(0, 0, 1);
            Vector3 speedControlVector = Vector3.Transform(new Vector3(0, 0, 1), miniMapMarkerNode.WorldTransformation * Matrix.Invert(speedMarkerNode.WorldTransformation)) -
                Vector3.Transform(new Vector3(0, 0, 0), miniMapMarkerNode.WorldTransformation * Matrix.Invert(speedMarkerNode.WorldTransformation));
            speedControlVector.X = 0; speedControlVector.Normalize();
            speedUpdateAngle = 180 * System.Math.Acos(Vector3.Dot(speedBaseVector, speedControlVector)) / System.Math.PI;
        }

        protected void initMap()
        {
            //outer square
            createWall(0, 0, 90f, 2f, 10f);//short edge at origin
            createWall(0, -110, 2f, 110f, 10f);// long edge at origin
            createWall((float)(9.0 - .2) * iniWallSize, -11 * iniWallSize, 2f, 110f, 10f);//long edge
            createWall(0, -110, 90f, 2f, 10f);//short edge

            //inner edge
            createWall((float)(9.0 - .2) * iniWallSize / 4, -8 * iniWallSize, 2f, 80f, 10f);
            createWall((float)(9.0 - .2) * iniWallSize * 2 / 4, -11 * iniWallSize, 2f, 80f, 10f);
            createWall((float)(9.0 - .2) * iniWallSize * 3 / 4, -8 * iniWallSize, 2f, 80f, 10f);
        }

        protected void createWall(float TranslationX, float TranslationY, float sizeX, float sizeY, float sizeZ)
        {
            //float TranslationXTemp = (iniWallSize * ScaleX - iniWallSize) / 2 + TranslationX;
            //float TranslationYTemp = (iniWallSize * ScaleY - iniWallSize) / 2 + TranslationY;
            float TranslationXTemp = (sizeX - iniWallSize) / 2 + TranslationX;
            float TranslationYTemp = (sizeY - iniWallSize) / 2 + TranslationY;

            // Create a geometry node with a model of a box that will be overlaid on
            // top of the ground marker array initially. (When the toolbar marker array is
            // detected, it will be overlaid on top of the toolbar marker array.)            
            wallNode[wallindex] = new GeometryNode("wall" + wallindex);
            //wallNode[wallindex].Model = new Box(iniWallSize);
            wallNode[wallindex].Model = new Box(sizeX, sizeY, sizeZ);

            // Make the sphere models interactable, which means that they
            // participate in the physical simulation
            wallNode[wallindex].Physics.Interactable = false;
            wallNode[wallindex].Physics.Collidable = true;
            wallNode[wallindex].Physics.Shape = ShapeType.Box;
            wallNode[wallindex].Physics.Mass = 1000f;
            wallNode[wallindex].AddToPhysicsEngine = true;

            // Make this box model cast and receive shadows
            wallNode[wallindex].Model.CastShadows = true;
            wallNode[wallindex].Model.ReceiveShadows = true;

            // Create a material to apply to the box model
            wallMaterial[wallindex] = new Material();
            wallMaterial[wallindex].Diffuse = Color.Green.ToVector4();
           // wallMaterial[wallindex].Diffuse = Color.TransparentWhite.ToVector4();
            wallMaterial[wallindex].Specular = Color.White.ToVector4();
            wallMaterial[wallindex].SpecularPower = 10;

            wallNode[wallindex].Material = wallMaterial[wallindex];

            wallTransNode[wallindex] = new TransformNode("wallTransNode" + wallindex);
            wallTransNode[wallindex].Translation = new Vector3(TranslationXTemp, TranslationYTemp, 5f)+ new Vector3(-40, 58, -1);

            //wallTransNode[wallindex].Scale = new Vector3(ScaleX, ScaleY, 1);


            if (debug)
                Console.WriteLine(wallTransNode[wallindex].Name + "!!!!!!!!!!!!!!!!!!!!!!1");

            // Add this box model node to the ground marker node
            realgroundNode.AddChild(wallTransNode[wallindex]);
            wallTransNode[wallindex].AddChild(wallNode[wallindex]);

            wallindex++;
        }


     /*   protected void initMap()
        {
            //outer square
            createWall(0, 0, 9.0f, .2f);//short edge at origin
            createWall(0, -11 * iniWallSize, .2f, 11.0f);// long edge at origin
            createWall((float)(9.0 - .2) * iniWallSize, -11 * iniWallSize, .2f, 11.0f);//long edge
            createWall(0, -11 * iniWallSize, 9.0f, .2f);//short edge

            //inner edge
            createWall((float)(9.0 - .2) * iniWallSize / 4, -8 * iniWallSize, .2f, 8.0f);
            createWall((float)(9.0 - .2) * iniWallSize * 2 / 4, -11 * iniWallSize, .2f, 8.0f);
            createWall((float)(9.0 - .2) * iniWallSize * 3 / 4, -8 * iniWallSize, .2f, 8.0f);
        }

        protected void createWall(float TranslationX, float TranslationY, float ScaleX, float ScaleY)
        {
            float TranslationXTemp = (iniWallSize * ScaleX - iniWallSize) / 2 + TranslationX;
            float TranslationYTemp = (iniWallSize * ScaleY - iniWallSize) / 2 + TranslationY;

            // Create a geometry node with a model of a box that will be overlaid on
            // top of the ground marker array initially. (When the toolbar marker array is
            // detected, it will be overlaid on top of the toolbar marker array.)            
            wallNode[wallindex] = new GeometryNode("wall" + wallindex);
            wallNode[wallindex].Model = new Box(iniWallSize);

            // Add this box model to the physics engine for collision detection
            wallNode[wallindex].AddToPhysicsEngine = true;
            wallNode[wallindex].Physics.Shape = ShapeType.Box;
            // Make this box model cast and receive shadows
            wallNode[wallindex].Model.CastShadows = true;
            wallNode[wallindex].Model.ReceiveShadows = true;

            // Create a material to apply to the box model
            wallMaterial[wallindex] = new Material();
            wallMaterial[wallindex].Diffuse = Color.Gray.ToVector4();
            wallMaterial[wallindex].Specular = Color.White.ToVector4();
            wallMaterial[wallindex].SpecularPower = 10;

            wallNode[wallindex].Material = wallMaterial[wallindex];

            wallTransNode[wallindex] = new TransformNode("wallTransNode" + wallindex);
            wallTransNode[wallindex].Translation = new Vector3(TranslationXTemp, TranslationYTemp, 5);
            wallTransNode[wallindex].Scale = new Vector3(ScaleX, ScaleY, 1);

            if(debug)
                Console.WriteLine(wallTransNode[wallindex].Name+"!!!!!!!!!!!!!!!!!!!!!!1");

            // Add this box model node to the ground marker node
            groundNode.AddChild(wallTransNode[wallindex]);
            wallTransNode[wallindex].AddChild(wallNode[wallindex]);
            

            wallindex++;
        }*/

        //keyboard operation for debugging
        private void KeyPressHandler(Keys keys, KeyModifier modifier)
        {
            // Detect key press "t"
            if (keys == Keys.T)
                travelMode = true;

            if (keys == Keys.N)
                travelMode = false;
            if (keys == Keys.Up)
                travelTranslationY += 0.5f;

        }


    }
}
